﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using QuickStart_Project_01.Base;
using QuickStart_Project_01.Chart;
using QuickStart_Project_01.Models;

namespace QuickStart_Project_01
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            InitMenus();
            this.DataContext = this;
        }

        #region 页面通知
        public event PropertyChangedEventHandler? PropertyChanged;
        #endregion


        #region 成员属性
        private FrameworkElement mainContent = new LineChartView();

        public FrameworkElement MainContent
        {
            get { return mainContent; }
            set
            {
                mainContent = value;
                PropertyChanged?.Invoke(this,new PropertyChangedEventArgs("MainContent"));
            }
        }

        public ObservableCollection<UMenuItem> Menus { get; set; } = new ObservableCollection<UMenuItem>();
        #endregion

        #region 命令
        [RelayCommand]
        public void Navigate(UMenuItem menuItem)
        {
            if (string.IsNullOrEmpty(menuItem.Url))
                return;
            Type? type = Type.GetType(menuItem.Url);
            if (type == null)
                return;
            MainContent = IocHelper.GetService<FrameworkElement>(type);
        }
        #endregion

        #region 本地方法
        private void InitMenus()
        {
            Menus.Clear();

            var dashboard = new UMenuItem
            {
                Id = 1,
                ParentId = 0,
                Name = "仪表盘",
                Icon = "\ue81f",
                Url = "QuickStart_Project_01.Chart.LineChartView",
                MenuItems = new ObservableCollection<UMenuItem>()
            };

            var reports = new UMenuItem
            {
                Id = 2,
                ParentId = 0,
                Name = "图表",
                Icon = "\ue742",
                Url = "",
                MenuItems = new ObservableCollection<UMenuItem>
                {
                    new UMenuItem
                    {
                        Id = 3,
                        ParentId = 2,
                        Name = "动态折线图",
                        Icon = "\ue6c1",
                        Url = "QuickStart_Project_01.Chart.LiveChartView"
                    },
                    new UMenuItem
                    {
                        Id = 4,
                        ParentId = 2,
                        Name = "柱状图",
                        Icon = "\ue642",
                        Url = "QuickStart_Project_01.Chart.BarChartView"
                    },
                    new UMenuItem
                    {
                        Id = 5,
                        ParentId = 2,
                        Name = "饼图",
                        Icon = "\ue642",
                        Url = "QuickStart_Project_01.Chart.PieChartView"
                    }
                }
            };

            var system = new UMenuItem
            {
                Id = 5,
                ParentId = 0,
                Name = "系统管理",
                Icon = "\ue6fb",
                Url = "/system",
                MenuItems = new ObservableCollection<UMenuItem>
        {
            new UMenuItem
            {
                Id = 6,
                ParentId = 5,
                Name = "用户管理",
                Icon = "\ue700",
                Url = "/system/users"
            },
            new UMenuItem
            {
                Id = 7,
                ParentId = 5,
                Name = "角色管理",
                Icon = "\ue709",
                Url = "/system/roles"
            },
            new UMenuItem
            {
                Id = 8,
                ParentId = 5,
                Name = "权限管理",
                Icon = "\ue702",
                Url = "/system/permissions"
            }
        }
            };

            var model3d = new UMenuItem
            {
                Id = 4,
                ParentId = 0,
                Name = "3D模型",
                Icon = "\ue60b",
                Url = "/Model3D",
            };

            Menus.Add(dashboard);
            Menus.Add(reports);
            Menus.Add(system);
            Menus.Add(model3d);
        }
        #endregion
    }
}